/*
* @Author: monster
* @Date:   2017-09-21 15:59:47
* @Last Modified by:   monster
* @Last Modified time: 2017-09-21 22:42:24
*/
'use strict';
angular.module('app').controller('registerCtrl', ['$state','$interval','$http', '$scope', function($state,$interval,$http, $scope){
	$scope.submit = function(){
		$http.post('data/regist.json',$scope.user).success(function(resp){
			$state.go('login');
		});
	};
	// 缓存定时器的值
	var count = 60;
	$scope.send = function(){
		// 发送json
		$http.get('data/code.json').success(function(resp){
			// 如果成功的话判断返回的state值是否为1
			if (resp.state===1) {
				// 是则赋值定时器为60，和time
				count = 60;
				$scope.time = '60s';
				// 开始循环定时器每秒一次
				var interval = $interval(function(){
					// 判断count是否>0
					if (count>0) {
						// 是则减一,重新定义time
						count--;
						$scope.time = count + 's';
					}else{
						// 否则停止定时器，将time置为空
						$interval.cancel(interval);
						$scope.time = '';
					}
				},1000)
			};
		}
		)
	};
}]);